package r5.powtorka6;

import java.util.Date;
import java.util.GregorianCalendar;

public class Employee extends Person {

	private Date hireDate;
	private double salary;

	public Employee(String name, int year, int month, int day, double salary) {
		super(name);
		this.hireDate = new GregorianCalendar(year, month - 1, day).getTime();
		this.salary = salary;
	}

	public void raiseSalary(double byPercent) {
		this.salary += this.salary * byPercent / 100;
	}

	public Date getHireDate() {
		return (Date) hireDate.clone();
	}

	public double getSalary() {
		return salary;
	}

	@Override
	public String toString() {
		return this.getClass().getSimpleName() + " " + this.getName() + ", "
				+ walutaFormatka.format(this.getSalary()) + ", "
				+ dataFormatka.format(this.hireDate);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((hireDate == null) ? 0 : hireDate.hashCode());
		long temp;
		temp = Double.doubleToLongBits(salary);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Employee other = (Employee) obj;
		if (hireDate == null) {
			if (other.hireDate != null)
				return false;
		} else if (!hireDate.equals(other.hireDate))
			return false;
		if (Double.doubleToLongBits(this.getSalary()) != Double
				.doubleToLongBits(other.getSalary()))
			return false;
		return true;
	}

}
